package com.tiger.web.controller.tool;

import com.tiger.common.core.controller.BaseController;
import com.tiger.project.domain.AssetMonth;
import com.tiger.project.service.IAssetMonthService;
import com.tiger.project.service.IAssetService;
import com.tiger.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 64601
 * @Description: 定时任务
 * @Date: 2023/2/15 15:06
 */
@RestController
public class TaskController extends BaseController {

    @Autowired
    private IAssetService assetService;

    @Autowired
    private IAssetMonthService assetMonthService;

    @Autowired
    private ISysDeptService sysDeptService;

//    @Scheduled(cron = "0 0/1 * * * ?")
    @Scheduled(cron = "0 0 0 1 * ?")
    private void assetMonth() {
        List<Long> companyIds = sysDeptService.getAllDeptId();
        if (companyIds.size() == 0 ) {
            return;
        }
        List<AssetMonth> res = assetService.getAssetsMonth(companyIds);
        if (res.size() == 0 ) {
            return;
        }
        assetMonthService.addAssetMonth(res);
    }
}
